package cn.sccdlg.springmvc.controller;

import cn.sccdlg.springmvc.exception.SysException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author RaoShuang
 * @emil 991207823@qq.com
 * @date 2020/10/24 21:01
 * 演示统一异常处理
 */
@Controller
@RequestMapping("/exception")
public class ExceptionController {

    @RequestMapping("/testException")
    public String testException() throws SysException {
        System.out.println("testException执行了...");
        try {
            // 模拟异常
            int a = 10 / 0;
        } catch (Exception e) {
            // 打印异常信息
            e.printStackTrace();
            // 抛出自定义异常信息
            throw new SysException("查询所有用户出现错误了...");
        }
        return "success";
    }
}
